const app = getApp();
Page({
    data: {
        BoxData:'',
        offLoad: true,
        startTime: '2017-09-01',
        endTime: '2017-09-01',
        startdate: '2017-09-01',
        enddate: '2017-09-01',
        done_money: 0.00,
        checkout_money:0.00,
        netErr: 0,
    },
    onLoad(options) {
        let myDate = new Date();
        let month = (Number(myDate.getMonth()) + 1) < 10 ? '0' + (Number(myDate.getMonth()) + 1) : (Number(myDate.getMonth()) + 1);
        this.setData({
            endTime: myDate.getFullYear() + '-' + month + '-' + myDate.getDate(),
            enddate: myDate.getFullYear() + '-' + month + '-' + myDate.getDate(),
        })
        this.confirmAjax();
    },
    /*时间筛选*/
    startDate: function (e) {
        this.setData({
            BoxData: '',
            offLoad: true,
            done_money: 0.00,
            checkout_money: 0.00,
            startdate: e.detail.value
        })
        this.confirmAjax();
    },
    endDate: function (e) {
        this.setData({
            BoxData: '',
            offLoad: true,
            done_money: 0.00,
            checkout_money: 0.00,
            enddate: e.detail.value
        })
        this.confirmAjax();
    },
    /*订单列表请求*/
    confirmAjax() {
        app.request.request({
            link: '/api/supplier/checkout_list',
            methodtype: 'GET',
            ting: {
                start_date: this.data.startdate,
                end_date: this.data.enddate,
                date_time:4,
                page: this.data.BoxData ? (this.data.BoxData.current_page + 1) : 1,
            },
            succ: (res) => {
                console.log(res)
                let Boxs = res.data.data, BoxMeta = res.data.message, BoxData = this.data.BoxData;
                if (res.data.status == 200) {
                    Boxs.bonus_order.data = BoxData[this.data.statusType] ? [...BoxData[this.data.statusType].bonus_order.data, ...Boxs.bonus_order.data] : [...Boxs.bonus_order.data];//列表拼接
                    Boxs.bonus_order.LoadMore = Boxs.bonus_order.last_page > Boxs.bonus_order.current_page ? 1 : Boxs.bonus_order.data.length != 0 ? 3 : 6;//状态保存
                    BoxData = Boxs.bonus_order;
                    this.setData({
                        BoxData: BoxData,
                        offLoad: true,
                        done_money: Boxs.done_money == 0 ? '0.00' : Boxs.done_money,
                        checkout_money: Boxs.checkout_money == 0 ? '0.00' : Boxs.checkout_money
                    })
                    console.log(this.data.BoxData)
                } else {
                    app.util.showModal(false, '提示', BoxMeta, () => wx.navigateBack({ delta: 1 }))
                }
            },
            fail: (err) => {
                this.setData({
                    netErr: 1,
                })
            },
            loadtype: this.data.BoxData ? 1 : 0,
        })
    },
    /*下拉加载*/
    lowerFlip() {
        if (this.data.BoxData.LoadMore == 1 && this.data.offLoad) {
            this.data.BoxData.LoadMore = 2;
            this.setData({
                BoxData: this.data.BoxData,
                offLoad: false,
            })
            this.orderListAjax();
        }
    },
    /*网络报错*/
    ErrorF5() {
        this.setData({
            BoxData: {},
            netErr: 0,
            offLoad: true,
        })
        this.orderListAjax();
    },
})